package thread;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/27
 * Time:20:49
 * 线程的++、--操作
 **/
public class ThreadDemo18 {
    static class Counter {
        //定义私有变量
        private int num = 0;

        //任务执行次数
        private final int maxSize = 100000;

        //num++
        public void increment() {
            for (int i = 0; i < maxSize; i++) {
                num++;
            }
        }

        //num--
        public void decrement() {
            for (int i = 0; i < maxSize; i++) {
                num--;
            }
        }

        public int getNum() {
            return num;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();

        counter.increment();
        counter.decrement();

        System.out.println("最终执行结果" + counter.getNum());
    }
}
